home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Emulatoren / warpsnes / theguis.lha / SNESLauncher.LZX / WarpSNES-Launcher.c < prev    next >
C/C++ Source or Header  |  1984-05-03  |  13KB  |  388 lines

  1. #include "demo.h"
  2.  
  3.  
  4. #define ID_ABOUT                1
  5. #define ID_NEWFILE              2
  6. #define ID_DOUBLENEWFILE        3
  7. #define ID_NEWVOLUME            4
  8. #define ID_MUTTER               5
  9. #define ID_DVIFILE              6
  10. #define ID_VIEW                 7
  11. #define ID_QUIT                 8
  12. struct NewMenu Menu[] =
  13. {
  14.         { NM_TITLE, "Project"  , 0 ,0,0,(APTR)0            },
  15.         { NM_ITEM , "About..." ,"?",0,0,(APTR)ID_ABOUT     },
  16.         { NM_ITEM , NM_BARLABEL, 0 ,0,0,(APTR)0            },
  17.         { NM_ITEM , "Quit"     ,"Q",0,0,(APTR)MUIV_Application_ReturnID_Quit },
  18.         { NM_END  , NULL       , 0 ,0,0,(APTR)0            },
  19. };
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. int CurPrtNum = 0;
  29.  
  30.  
  31. APTR Applic = NULL;
  32. APTR WI_Main;
  33.  
  34.  
  35.  
  36. APTR LV_Files, LV_Volumes, BT_Parent, ST_File, IM_File, BT_View, BT_End;
  37.  
  38.  
  39.  
  40.  
  41.  
  42. static char DVIFileBuffer[512];
  43. static char DVIpattern[16];
  44.  
  45.  
  46.  
  47.  
  48. #define POP_FILE        1
  49. #define POP_OUTP        2
  50. #define POP_LOGF        3
  51.  
  52.  
  53. #define PopupArg(ptr,obj,retimg,img,hook,arg)\
  54.         HGroup, GroupSpacing(1),\
  55.                 Child, ptr=obj,\
  56.                 Child, retimg = ImageObject,\
  57.                         ImageButtonFrame,\
  58.                         MUIA_Image_Spec          , img,\
  59.                         MUIA_Image_FontMatchWidth, TRUE,\
  60.                         MUIA_Image_FreeVert      , TRUE,\
  61.                         MUIA_InputMode           , MUIV_InputMode_RelVerify,\
  62.                         MUIA_Background          , MUII_BACKGROUND,\
  63.                         End,\
  64.                 TAG_IGNORE, retimg && ptr ? DoMethod(retimg,MUIM_Notify,MUIA_Pressed,FALSE,ptr,3,MUIM_CallHook,hook,arg) : 0,\
  65.                 End
  66.  
  67.  
  68. SAVEDS ASM ULONG FilePopupFunc(REG(a0) struct Hook * hook, REG(a1) void * args, REG(a2) APTR obj)
  69. {
  70.   struct Window * window;
  71.   long l, t, w, h;
  72.   struct FileRequester * req;
  73.   char * buf, * cptr, * dir, * file;
  74.   int IsDir, GadType;
  75.   BPTR lock;
  76.   __aligned struct FileInfoBlock fib;
  77.   char device[50];
  78.   char * title = "";
  79.   
  80.   /* put our application to sleep while displaying the requester */
  81.   set(Applic,MUIA_Application_Sleep,TRUE);
  82.   
  83.   GadType = *((long *)args);    /* POP_#? */
  84.  
  85.   switch (GadType) {
  86.     case POP_FILE:
  87.       title = "Select Mp3Song";
  88.       break;
  89.     case POP_OUTP:
  90.       title = "Select Output-File";
  91.       break;
  92.     case POP_LOGF:
  93.       title = "Select Logfile";
  94.       break;
  95.   }
  96.  
  97.   get(obj,MUIA_String_Contents,&buf);
  98.   strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
  99.   
  100.   IsDir = FALSE;
  101.   lock = Lock(DVIFileBuffer, ACCESS_READ);
  102.   if (lock) {
  103.     if (Examine(lock, &fib)) {
  104.       if (fib.fib_DirEntryType > 0) IsDir = TRUE;
  105.     }
  106.     UnLock(lock);
  107.   }
  108.  
  109.   if (IsDir) {
  110.     file = NULL;
  111.     dir  = DVIFileBuffer;
  112.   }
  113.   else {
  114.     cptr = strrchr(DVIFileBuffer, '/');
  115.     if (cptr) {
  116.       dir = DVIFileBuffer;
  117.       *cptr = '\0';
  118.       file  = cptr+1;
  119.     }
  120.     else {
  121.       cptr = strchr(DVIFileBuffer, ':');
  122.       if (cptr) {
  123.         strncpy(device, DVIFileBuffer, cptr-DVIFileBuffer+1);
  124.         device[cptr-DVIFileBuffer+1] = '\0';
  125.         dir  = device;
  126.         file = cptr+1;
  127.       }
  128.       else {
  129.         dir  = NULL;
  130.         file = DVIFileBuffer;
  131.       }
  132.     }
  133.   }
  134.   
  135.   /* get the calling objects window and position */
  136.   get(obj,MUIA_Window  ,&window);
  137.   get(obj,MUIA_LeftEdge,&l);
  138.   get(obj,MUIA_TopEdge ,&t);
  139.   get(obj,MUIA_Width   ,&w);
  140.   get(obj,MUIA_Height  ,&h);
  141.  
  142.   if (req=MUI_AllocAslRequestTags(ASL_FileRequest,TAG_DONE)) {
  143.     if (MUI_AslRequestTags(req,
  144.          ASLFO_Window         ,window,
  145.          ASLFO_PrivateIDCMP   ,TRUE,
  146.          ASLFO_TitleText      ,title,
  147.          ASLFO_InitialLeftEdge,window->LeftEdge + l,
  148.          ASLFO_InitialTopEdge ,window->TopEdge  + t+h,
  149.          ASLFO_InitialWidth   ,w,
  150.          ASLFO_InitialHeight  ,250,
  151.          ((GadType==POP_FILE) ? ASLFR_InitialPattern : TAG_IGNORE), "#?.smc",
  152.          ((file)              ? ASLFR_InitialFile    : TAG_IGNORE), file,
  153.          ((dir)               ? ASLFR_InitialDrawer  : TAG_IGNORE), dir,
  154.          TAG_DONE)) {
  155.  
  156.        /* set the new contents for our string gadget */
  157.        strncpy(DVIFileBuffer, req->fr_Drawer, sizeof(DVIFileBuffer)-1);
  158.        AddPart(DVIFileBuffer, req->fr_File, sizeof(DVIFileBuffer)-1);
  159.        set(obj,MUIA_String_Contents,DVIFileBuffer);
  160.  
  161.        if (GadType == POP_FILE) {
  162.                         set(LV_Files, MUIA_Dirlist_Directory, req->fr_Drawer);
  163.        }
  164.     }
  165.     MUI_FreeAslRequest(req);
  166.   }
  167.  
  168.   /* wake up our application again */
  169.   set(Applic,MUIA_Application_Sleep,FALSE);
  170.  
  171.   return(0);
  172. }
  173.  
  174.  
  175. static struct Hook FilePopupHook = {
  176.         {NULL, NULL},
  177.         (void *)FilePopupFunc,
  178.         NULL, NULL
  179. };
  180.  
  181.  
  182. /******************************************************/
  183.  
  184.  
  185.  
  186.  
  187. int main(int argc, char * argv[])
  188. {
  189.    init();
  190.  
  191.   /*InitVars(); */
  192.  
  193.  
  194.   { /* Homedirectory in String-Gadget */
  195.     BPTR lock;
  196.     lock = Lock("", ACCESS_READ);
  197.     if (lock) {
  198.       (void)NameFromLock(lock, DVIFileBuffer, sizeof(DVIFileBuffer)-1);
  199.       UnLock(lock);
  200.     }
  201.     else {
  202.       *DVIFileBuffer = '\0';
  203.     }
  204.   }
  205.  
  206.   (void)ParsePatternNoCase("#?", DVIpattern, 16);
  207.  
  208.  
  209.   Applic = ApplicationObject,
  210.                 MUIA_Application_Title         , " WarpSNES PPC Launcher V1.0",
  211.                 MUIA_Application_Version       , "$VER: ",
  212.                 MUIA_Application_Copyright     , "Copyright ©1998, Sinan Gurkan",
  213.                 MUIA_Application_Author        , "Sinan Gürkan",
  214.                 MUIA_Application_Description   , "warpsnes",
  215.                 MUIA_Application_Base          , "snes",
  216.                 MUIA_Application_Menu          , Menu,
  217.                         
  218.  
  219.  
  220.                 SubWindow,
  221.                         WI_Main = WindowObject,
  222.                         MUIA_Window_Title , "WarpSNES Launcher GUI",
  223.                         MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  224.  
  225.                         WindowContents, VGroup, 
  226.                           Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Text_Contents, "\33c\33b\0338WarpSNES PPC Launcher\nWritten 31.7.1998 by Sinan Gurkan\nFeel The PPC Power !",  End,
  227.  
  228.                                Child, VGroup, GroupFrameT("Select SNES ROM file"),
  229.                                 Child, HGroup,
  230.                                         Child, LV_Files = ListviewObject,
  231.                                                         MUIA_Weight, 300,
  232.                                                         MUIA_Listview_Input, TRUE,
  233.                                                         MUIA_Listview_List, DirlistObject,
  234.                                                         InputListFrame,
  235.                                                         MUIA_Dirlist_Directory, DVIFileBuffer, 
  236.                                                         MUIA_Dirlist_AcceptPattern, DVIpattern,
  237.                                                         MUIA_Dirlist_RejectIcons, TRUE, End,
  238.                                                         End,
  239.                                         Child, VGroup,
  240.                                           Child, LV_Volumes = ListviewObject,
  241.                                                                 MUIA_Weight, 200,
  242.                                                                 MUIA_Listview_Input, TRUE,
  243.                                                                 MUIA_Listview_List, VolumelistObject, 
  244.                                                                 InputListFrame, End,
  245.                                                                 End,
  246.                                           Child, BT_Parent = SimpleButton("_Parent"),
  247.                                           End,
  248.                                         End,
  249.                                 Child, PopupArg(ST_File, String(DVIFileBuffer,sizeof(DVIFileBuffer)), IM_File, MUII_PopFile, &FilePopupHook, POP_FILE),
  250.                                 Child, BT_View = SimpleButton("_Start EMulation"),
  251.                                 End,
  252.                         
  253.                         
  254.                               End,
  255.                         
  256.                         
  257.                         
  258.                             End,
  259.                           
  260.                         
  261.                 
  262.            End;
  263.  
  264.  
  265.   if (!Applic) fail(Applic, "Failed to create application.");
  266.  
  267.  
  268.   DoMethod(WI_Main,MUIM_Window_SetCycleChain,ST_File,IM_File,LV_Files,BT_Parent,LV_Volumes,BT_View,BT_End,NULL);
  269.  
  270.   
  271.  
  272.   DoMethod(LV_Volumes ,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,Applic,2,MUIM_Application_ReturnID,ID_NEWVOLUME);
  273.   DoMethod(LV_Files,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,Applic,2,MUIM_Application_ReturnID,ID_NEWFILE);
  274.   DoMethod(LV_Files,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,Applic,2,MUIM_Application_ReturnID,ID_DOUBLENEWFILE);
  275.   DoMethod(BT_Parent,MUIM_Notify,MUIA_Pressed,FALSE,Applic,2,MUIM_Application_ReturnID,ID_MUTTER);
  276.   DoMethod(ST_File,MUIM_Notify,MUIA_String_Acknowledge, MUIV_EveryTime,Applic,2,MUIM_Application_ReturnID,ID_DVIFILE);
  277.   DoMethod(BT_View,MUIM_Notify,MUIA_Pressed,FALSE,Applic,2,MUIM_Application_ReturnID,ID_VIEW);
  278.   DoMethod(BT_End,MUIM_Notify,MUIA_Pressed,FALSE,Applic,2,MUIM_Application_ReturnID,ID_QUIT);
  279.  
  280.   DoMethod(WI_Main,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,Applic,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  281.   DoMethod(WI_Main,    MUIM_Notify,MUIA_Window_InputEvent, "control c", Applic,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  282.   
  283.   set(WI_Main,MUIA_Window_Open,TRUE);
  284.  
  285.   {
  286.     ULONG signal, retsig;
  287.     BOOL running = TRUE;
  288.     char sinan[256];
  289.     
  290.     char * buf, * cptr;
  291.     BPTR lock;
  292.     __aligned struct FileInfoBlock * pfib;
  293.     int id;
  294.  
  295.     while (running) {
  296.       id = DoMethod(Applic,MUIM_Application_Input,&signal);
  297.       switch (id) {
  298.           case MUIV_Application_ReturnID_Quit:
  299.                 running = FALSE;
  300.                 break;
  301.  
  302.           case ID_ABOUT:
  303.                 MUI_Request(Applic, WI_Main, 0, NULL, "I See..", "WarpSNES Launcher By Sinan Gurkan");
  304.                 break;
  305.  
  306.           case ID_NEWFILE:
  307.                 get(LV_Files,MUIA_Dirlist_Path, &buf);
  308.                 if (buf) {
  309.                         strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
  310.                         set(ST_File,MUIA_String_Contents,DVIFileBuffer);
  311.                 }
  312.                 break;
  313.  
  314.           case ID_DOUBLENEWFILE:
  315.                 DoMethod(LV_Files,MUIM_List_GetEntry,-1,&pfib);
  316.                 get(LV_Files,MUIA_Dirlist_Path, &buf);
  317.                 strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
  318.                 set(ST_File,MUIA_String_Contents,DVIFileBuffer);
  319.                 if (pfib->fib_DirEntryType > 0) {
  320.                   set(LV_Files,MUIA_Dirlist_Directory,buf);
  321.                 }
  322.                 break;
  323.  
  324.           case ID_NEWVOLUME:
  325.                 DoMethod(LV_Volumes,MUIM_List_GetEntry,-1,&buf);
  326.                 set(LV_Files,MUIA_Dirlist_Directory,buf);
  327.                 break;
  328.  
  329.           case ID_MUTTER:
  330.                 DoMethod(LV_Files,MUIM_List_GetEntry,-1,&pfib);
  331.                 get(ST_File,MUIA_String_Contents,&buf);
  332.                 strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
  333.                 cptr = strrchr(DVIFileBuffer, '/');
  334.                 if (pfib->fib_DirEntryType < 0 && cptr) {
  335.                   *cptr = '\0';
  336.                   cptr = strrchr(DVIFileBuffer, '/');
  337.                 }
  338.                 if (!cptr) cptr = strchr(DVIFileBuffer, ':');
  339.                 if (cptr) {
  340.                   if (*cptr == ':') cptr++;
  341.                   *cptr = '\0';
  342.                 }
  343.                 set(ST_File,MUIA_String_Contents,DVIFileBuffer);
  344.                 set(LV_Files,MUIA_Dirlist_Directory,DVIFileBuffer);
  345.                 break;
  346.  
  347.           case ID_DVIFILE:
  348.                 get(ST_File,MUIA_String_Contents,&buf);
  349.                 lock = Lock(buf, ACCESS_READ);
  350.                 if (!lock) {
  351.                   set(ST_File,MUIA_String_Contents,DVIFileBuffer);
  352.                 }
  353.                 else {
  354.                   UnLock(lock);
  355.                   lock = NULL;
  356.                   strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
  357.                   set(LV_Files, MUIA_Dirlist_Directory, DVIFileBuffer);
  358.                 }
  359.                 break;
  360.         
  361.          case ID_VIEW:
  362.                 
  363.                 system("stack 600000");
  364.                 sprintf(sinan,"warpsnes -nosound -speedhacks -nosecondjoy %s", DVIFileBuffer);
  365.                 system(sinan);
  366.                
  367.                                
  368.                 break;  
  369.  
  370.         case ID_QUIT:
  371.  
  372.                 break;
  373.            
  374.                         
  375.       }
  376.       if (signal)
  377.         {
  378.         retsig = Wait(signal | SIGBREAKF_CTRL_C);
  379.         if (retsig & SIGBREAKF_CTRL_C) running = FALSE;
  380.         }
  381.     }
  382.   }
  383.  
  384.  
  385.   
  386.   fail(Applic,NULL);
  387. }
  388.